import api from 'api/sale'

// state
let state = {
  saleDataStatistics: {},
  getSalespersonStudentList: {},
  getSaleStudent: {},
  getFollowRecordList: {},
  getStudentTestClassList: []
}

// getters
const getters = {
  saleDataStatistics: state => state.saleDataStatistics,
  getSalespersonStudentList: state => state.getSalespersonStudentList,
  getSaleStudent: state => state.getSaleStudent,
  getFollowRecordList: state => state.getFollowRecordList,
  getStudentTestClassList: state => state.getStudentTestClassList
}

// actions
const actions = {
  saleDataStatistics ({ commit, state }, params) { // 获取列表
    return api.saleDataStatistics(params).then((json) => {
      commit('SALE_DATA_STATISTICS', {
        params: params,
        data: json.data
      })
    })
  },
  getSalespersonStudentList ({ commit, state }, params) {
    return api.getSalespersonStudentList(params).then((json) => {
      commit('GET_SALESPERSON_STUDEN_LIST', {
        params: params,
        data: json.data
      })
    })
  },
  getSaleStudent ({ commit, state }, params) {
    return api.getSaleStudent(params).then((json) => {
      commit('GET_SALE_STUDENT', {
        params: params,
        data: json.data
      })
    })
  },
  getFollowRecordList ({ commit, state }, params) {
    return api.getFollowRecordList(params).then((json) => {
      commit('GET_FOLLOW_RECORD_LIST', {
        params: params,
        data: json.data
      })
    })
  },
  getStudentTestClassList ({ commit, state }, params) {
    return api.getStudentTestClassList(params).then((json) => {
      commit('GET_STUDENT_TEST_CLASS_LIST', {
        params: params,
        data: json.data
      })
    })
  }
}

// mutations
const mutations = {
  SALE_DATA_STATISTICS (state, { data }) {
    state.saleDataStatistics = data
  },
  GET_SALESPERSON_STUDEN_LIST (state, { data }) {
    state.getSalespersonStudentList = data.list
  },
  GET_SALE_STUDENT (state, { data }) {
    state.getSaleStudent = data
  },
  GET_FOLLOW_RECORD_LIST (state, { data }) {
    state.getFollowRecordList = data
  },
  GET_STUDENT_TEST_CLASS_LIST (state, { data }) {
    state.getStudentTestClassList = data.list
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
